/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.matrimonysite.sessionbean;

import com.matrimonysite.entity.UserPayment;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author khanhnguyen
 */
@Stateless
public class UserPaymentFacade extends AbstractFacade<UserPayment> {

    @PersistenceContext(unitName = "MatrimonySite-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public UserPaymentFacade() {
        super(UserPayment.class);
    }

    @Override
    public void create(UserPayment userpayment) {
        em.persist(userpayment);
    }

    @Override
    public void edit(UserPayment userpayment) {
        em.merge(userpayment);
    }

    @Override
    public void remove(UserPayment userpayment) {
        em.remove(em.merge(userpayment));
    }

    public UserPayment getPaymentID(String paymentID) {
        UserPayment payment = null;
        try {
            Query q = em.createNamedQuery("UserProfile.findByProfileID");
            q.setParameter("paymentID", paymentID);
            payment = (UserPayment) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return payment;
    }

    public UserPayment getPayGate(String payGate) {
        UserPayment payment = null;
        try {
            Query q = em.createNamedQuery("UserProfile.findByProfileID");
            q.setParameter("payGate", payGate);
            payment = (UserPayment) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return payment;
    }

    public UserPayment getAccountID(String acccountID) {
        UserPayment payment = null;
        try {
            Query q = em.createNamedQuery("UserProfile.findByProfileID");
            q.setParameter("acccountID", acccountID);
            payment = (UserPayment) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return payment;
    }

    public UserPayment getTotalMoney(String totalMoney) {
        UserPayment payment = null;
        try {
            Query q = em.createNamedQuery("UserProfile.findByProfileID");
            q.setParameter("totalMoney", totalMoney);
            payment = (UserPayment) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return payment;
    }

    public UserPayment getCreatedAt(String createdAt) {
        UserPayment payment = null;
        try {
            Query q = em.createNamedQuery("UserProfile.findByProfileID");
            q.setParameter("createdAt", createdAt);
            payment = (UserPayment) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return payment;
    }

     public List<UserPayment> getAllUserPayment(){
        Query query= em.createNamedQuery("UserPayment.findAll");
        return query.getResultList();
    }
}
